#include<iostream>
using namespace std;
string Haab[20]={"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu","uayet"};
string Tzolkin[20]={"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};
int days;
int getDay(string str){
    int len=str.size();int res=0;
    for(int i=0;i<len-1;i++){
        res=res*10+str[i]-'0';
    }
    return res;
}
int getMonth(string b){
    for(int i=0;i<20;i++){
        if(b==Haab[i]){
            return i;
        }
    }
}
string getMonth2(int m){
    return Tzolkin[m];
}
int t;
int main(){  
    //B:玛雅历  
    cin>>t;
    cout<<t<<endl;
    while(t--){
        string a,b;int y;
        cin>>a>>b>>y;
        int d=getDay(a);
        int m=getMonth(b);
        days=0;
        //算出这一天前的全部天数
        for(int i=0;i<y;i++){
            days+=365;
        }
        for(int i=0;i<m;i++){
            days+=20;
        }
        days+=d;
        // cout<<days<<endl;
        //转换成Tzolkin
        int d2,m2,y2;string m2_s;
        y2=days/260;
        //存这一年开始到这一天的全部天数
        int temp=days%260;
        d2=temp%13;
        m2=temp%20;
        m2_s=getMonth2(m2);
        cout<<d2+1<<" "<<m2_s<<" "<<y2<<endl;
    }
    return 0;
}